// import router from "@/router";
// import type { ActionContext } from "vuex";
// import config from "@/config";
// import deepClone from "@/libs/deepClone";
// import { RootState } from ".";
// let customRouter = deepClone(config.router) as typeof config.router


// export type AsideState = {
//   currentAside: CustomRoute,
//   asideList: CustomRoute[],
// }
// export type AsideContext = ActionContext<AsideState, RootState>


// const state: AsideState = {
//   currentAside: customRouter[0],
//   asideList: customRouter,
// }

// const mutations = {
//   a: (state: AsideState, data: number) => {
//     console.log(data);

//   },
//   SETAsideList(state: AsideState, data: CustomRoute[]) {
//     state.asideList = data
//     // console.log('设置了侧边栏数据：', data);
//   },
//   SETCurrentAside(state: AsideState, data: CustomRoute) {
//     if (data) {
//       state.currentAside = data
//       // console.log('点击右边侧边栏：', data);
//     }
//   }
// }

// const actions = {
//   HANDLE_asideSplit_click({ state, commit, rootGetters }: AsideContext, data: { asideSplit: CustomRoute, current?: CustomRoute }) {
//     let { asideSplit, current } = data
//     commit('SETCurrentAside', asideSplit)
//     // 点击最左侧侧边栏
//     // router.push(current ? current.path : asideSplit.path)
//   },
//   HANDLE_aside_click({ state, commit, rootGetters }: AsideContext, data: CustomRoute) {
//     // console.log('aside 点击', data);
//     router.push({
//       name: data.name
//     })
//   }
// }

// const getters = {
//   asideList: (state: AsideState) => state.asideList,
//   currentAside: (state: AsideState) => state.currentAside,
// }

// export default {
//   namespaced: true, // 声明命名空间
//   state,
//   mutations,
//   actions,
//   getters
// }

import router from "@/router";
import type { ActionContext } from "vuex";
import config from "@/config";
import deepClone from "@/libs/deepClone";
import { RootState } from ".";
let customRouter = deepClone(config.router) as CustomRoute[]

export type AsideState = {
  currentAside: CustomRoute,
  asideList: CustomRoute[],
  openKeys: string[],
  selectedKeys: string[],
  userAsideList: Pm.UserFun[],
}
export type AsideContext = ActionContext<AsideState, RootState>


const state: AsideState = {
  currentAside: customRouter[0],
  asideList: customRouter,
  openKeys: customRouter.length ? [customRouter[0].name] : [],
  /**存储路由的meta中的name */
  selectedKeys: [],
  userAsideList: [{
    createTime: "2022-10-20 10:20:30",
    dictCode: "0009",
    dictDesc: null,
    dictName: "我的考核",
    dictTypeCode: "002",
    dictValue: null,
    id: 9,
    sort: "5",
    status: "1"
  }]
}

const mutations = {
  SETAsideList(state: AsideState, data: CustomRoute[]) {
    console.log('设置了侧边栏数据：', data);
    state.asideList = data
  },
  SETCurrentAside(state: AsideState, data: CustomRoute) {
    console.log('点击右边侧边栏：', data);
    state.currentAside = data
  },
  SETOPENKEYS(state: AsideState, data: string[]) {
    console.log('设置被打开了的侧边栏', data);
    state.openKeys = data
  },
  SETSELECTEDKEYS(state: AsideState, data: string) {
    console.log('设置被选择了的侧边栏', data, location);
    state.selectedKeys = data ? [data] : []
  }
}

const actions = {
  MENUCLICK({ state, commit, rootGetters }: AsideContext, data: string) {
    // console.log('aside 点击', data);
    commit('SETSELECTEDKEYS', data)
  },
  MENUCHANGE({ state, commit, rootGetters }: AsideContext, data: string[]) {
    // console.log('aside 变化', data);
    commit('SETOPENKEYS', data)
  },
}

const getters = {
  /**根据用户界面配置，来选择性的导出侧边栏 */
  asideList: (state: AsideState) => state.asideList,
  userAsideList: (state: AsideState) => state.userAsideList,
  currentAside: (state: AsideState) => state.currentAside,
  openKeys: (state: AsideState) => state.openKeys,
  selectedKeys: (state: AsideState) => state.selectedKeys,
}

export default {
  namespaced: true, // 声明命名空间
  state,
  mutations,
  actions,
  getters
}